<?php 
if(!isset($filtro_categoria)){
	$filtro_categoria = set_value("filtro_categoria","");
}

if(!isset($data_de) || $data_de==''){
	$data_de = set_value("data_de",date("01/m/Y"));
}

?>


<form id="formulario_filtro">
	<table>
		<tr>
			<td>
				<?php echo form_label("Categoria","filtro_categoria");?>
			</td>
			<td colspan="3">
				<?php echo form_dropdown("filtro_categoria",$categorias,$filtro_categoria)?>
			</td>
		</tr>
		<tr>
			<td>
				<?php echo form_label("Data de","data_de");?>
			</td>
			<td>
				<?php echo form_input(array("name"=>"data_de","id"=>"data_de","readonly"=>"readonly","size"=>"10"), $data_de)?>
			</td>
			<td>
				<?php echo form_label("Data ate","data_ate");?>
			</td>
			<td>
				<?php echo form_input(array("name"=>"data_ate","id"=>"data_ate","readonly"=>"readonly","size"=>"10"), $data_ate)?>
			</td>
			<td>
				<?php echo form_button(array("onclick"=>"tabela();"),"Filtrar");?>
			</td>
		</tr>
	</table>
</form>
<br/>

<?php
if(isset($gastos)){
	?>
	<h2>Tabela de lançamentos</h2>
	<table width="100%" class="gastos">
		<tr>
			<th>
				Nome
			</th>
			<th width="60">
				Valor
			</th>
			<th width="100">
				Categoria
			</th>
			<th width="90">
				Data
			</th>
			<th width="100">
				Ações
			</th>
		</tr>
		<?php 
			foreach ($gastos as $g) {
				echo "<tr>
						<td>&nbsp;&nbsp;
							{$g->nome}
						</td>
						<td>&nbsp;&nbsp;
							{$g->valor}
						</td>
						<td>&nbsp;&nbsp;
							{$g->categoria}
						</td>
						<td>&nbsp;&nbsp;
							{$g->data_cadastro}
						</td>
						<td>&nbsp;&nbsp;
							<a href='javascript:editar({$g->id});'>Editar</a>
							&nbsp;&nbsp;
							<a href='javascript:excluir({$g->id});'>Excluir</a>
						</td>
					  </tr>";
			}
		?>
    </table>
    <?php 
}else{
	echo "<h2><span>Nao possui gastos cadastrados.</span></h2>";
}
?>